package Text_80;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class Code {

	public static void main(String[] args) throws IOException {
		 /*
	        * 将文件中数据 2-5-1-3-8-6 排序变成 1-2-3-5-6-8
	        * */
	        //读取纯文本文件
	        FileReader fr = new FileReader("src\\day11\\a.txt");
	        //读出的数据放入 sb
	        StringBuilder sb = new StringBuilder();
	        int len;
	        while((len = fr.read())!=-1){

	            sb.append((char)len);
	        }
	        fr.close();
	        //System.out.println(sb);
	        //转换成字符串
	        String s = sb.toString();
	        //分割
	        String[] sp = s.split("-");
	        ArrayList<Integer> list = new ArrayList<>();
	        for(String arr : sp){
	            int i = Integer.parseInt(arr);
	            list.add(i);
	        }
	        //自动排序
	        Collections.sort(list);
	        System.out.println(list);
	        FileWriter fw = new FileWriter("src\\day11\\aa.txt");
	        for (int i = 0; i < list.size(); i++) {
	            if(i ==list.size()-1){
	                //注意：写入文件的是字符串
	                fw.write(list.get(i)+"");
	            }else{
	                fw.write(list.get(i)+"-");
	            }
	        }
	        fw.close();

	}

}
